package com.example.serviceconsumer.controller;

import com.example.serviceconsumer.client.ProductClientA;
import com.example.serviceconsumer.client.ProductClientB;
//import com.example.serviceconsumer.client.ProductFeignClient;
import com.example.serviceconsumer.model.Product;
import com.example.serviceconsumer.service.ProductResilienceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consumer/feign/products")
public class FeignDemoController {

//    private final ProductFeignClient productFeignClient;

    private final ProductResilienceService productResilienceService;

    //构造方法
    @Autowired
    public FeignDemoController(ProductResilienceService productResilienceService) {
        this.productResilienceService = productResilienceService;
    }

//

    @GetMapping
    public ResponseEntity<List<Product>> getAllProducts() {
        System.out.println("Consumer (Feign): GET /products protected call");
        return productResilienceService.getAllProductsWithBulkhead();
    }

    @GetMapping("/{id}")
    public ResponseEntity<Product> getProductById(@PathVariable Long id) {
        System.out.println("Consumer (Feign): GET /products/" + id + " protected call");
        return productResilienceService.getProductByIdWithRateLimiter(id);
    }
}
//

    // GET: 获取所有产品
//    @GetMapping
//    public ResponseEntity<List<Product>> getAllProducts() {
//        System.out.println("Consumer (Feign): GET /products");
//        return productFeignClient.getAllProducts();
//    }
//
//    // GET: 根据ID获取产品
//    @GetMapping("/{id}")
//    public ResponseEntity<Product> getProductById(@PathVariable Long id) {
//        System.out.println("Consumer (Feign): GET /products/" + id);
//        return productFeignClient.getProductById(id);
//    }
//
//    // POST: 创建新产品
//    @PostMapping
//    public ResponseEntity<Product> createProduct(@RequestBody Product newProduct) {
//        System.out.println("Consumer (Feign): POST /products with " + newProduct);
//        return productFeignClient.createProduct(newProduct);
//    }
//
//    // PUT: 更新产品
//    @PutMapping("/{id}")
//    public ResponseEntity<Product> updateProduct(@PathVariable Long id, @RequestBody Product updatedProduct) {
//        System.out.println("Consumer (Feign): PUT /products/" + id + " with " + updatedProduct);
//        return productFeignClient.updateProduct(id, updatedProduct);
//    }
//
//    // DELETE: 删除产品
//    @DeleteMapping("/{id}")
//    public ResponseEntity<Void> deleteProduct(@PathVariable Long id) {
//        System.out.println("Consumer (Feign): DELETE /products/" + id);
//        return productFeignClient.deleteProduct(id);
//    }
